<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('立体库盘点日报')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width: 200px!important;
        }
        .el-input__icon {
            line-height: 0!important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li v-if="checkedSearch.indexOf('物料编码') != -1">
                            物料编码：<input type="text" name="itemCode"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('物料名称') != -1">
                            物料名称：
                            <select name="itemId">
                                <option value="">全部</option>
                                <option v-for="(item, index) in items" :key="index" :value="item.itemId" v-cloak>{{item.itemName}}</option>
                            </select>
                        </li>
                        <li v-show="checkedSearch.indexOf('操作时间') != -1">
                            <label>操作时间：</label>
                            <el-date-picker
                                name="startTime"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-model="startTimeValue"
                                type="datetime"
                                @change="compare"
                                placeholder="开始时间">
                            </el-date-picker>
                            <span>-</span>
                            <el-date-picker
                                name="endTime"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-model="endTimeValue"
                                type="datetime"
                                @change="compare"
                                placeholder="结束时间">
                            </el-date-picker>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" :class="flag ? 'disabled' : ''" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" @click="moreSearch()"><i class="fa fa-edit"></i>&nbsp;更多</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="takeStockDaily:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "takeStockDaily";

    const searchOptions = ['物料编码', '物料名称','操作时间'];

    var app = new Vue({
        el: '.container-div',
        data: {
            showMore: false,
            checkAll: false,
            checkedSearch: ['物料名称', '操作时间'],
            searches: searchOptions,
            isIndeterminate: true,
            items: [],
            startTimeValue: '',
            endTimeValue: '',
            flag: false
        },
        methods: {
            compare: function(){
                if(this.startTimeValue != '' && this.endTimeValue != ''){
                    if(this.startTimeValue != null && this.endTimeValue != null){
                        var a = new Date(this.startTimeValue);
                        var b = new Date(this.endTimeValue);
                        if(a > b){
                            $.modal.alertWarning("结束时间需大于开始时间");
                            this.flag = true;
                        }else{
                            this.flag = false;
                        }
                    }else if(this.startTimeValue == null){
                        this.startTimeValue = '';
                        this.flag = false;
                    }else if(this.endTimeValue == null){
                        this.endTimeValue = '';
                        this.flag = false;
                    }
                }
            },
            getItems: function(){
                var that = this;
                var item = that.item;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/itemInfo/findList",
                    data: {},
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.items = data.rows;
                    }
                });
            },
            moreSearch(){
                this.showMore = true;
            },
            handleCheckAllChange(val){
                this.checkedSearch = val ? searchOptions : [];
                this.isIndeterminate = false;
            },
            handleCheckedSearchChange(value){
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.searches.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.searches.length;
            },
            getBeforeDate(n){
                var d = new Date();
                var year = d.getFullYear();
                var mon = d.getMonth() + 1;
                var day = d.getDate();
                if(day <= n) {
                    if(mon > 1) {
                        mon = mon - 1;
                    } else {
                        year = year - 1;
                        mon = 12;
                    }
                }
                d.setDate(d.getDate() - n);
                year = d.getFullYear();
                mon = d.getMonth() + 1;
                day = d.getDate();
                s = year + "-" + mon + "-" + day;
                return s;
            },
        },
        created(){
            this.getItems();
            this.startTimeValue = this.getBeforeDate(1) + " 00:00:00";
            this.endTimeValue = this.getBeforeDate(0) + " 00:00:00";
        }
    })

    $(function () {
        var options = {
            url: prefix + "/findList",
            exportUrl: prefix + "/export",
            modalName: "立体库盘点日报",
            showExport: false,
            queryParams: queryParams,
            columns: [
                {
                    field: 'itemCode',
                    title: '物料编码',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'itemName',
                    title: '物料名称',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'boxQuantity',
                    title: '库存数量',
                    align: 'center',
                    visible: true,
                    formatter: function(value, row, index){
                        if(value == null){
                            return 0;
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'billInTaskQuantity',
                    title: '实际入库量',
                    align: 'center',
                    visible: true,
                    formatter: function(value, row, index){
                        if(value == null){
                            return 0;
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'billOutQuantity',
                    title: '出库单计划出货数',
                    align: 'center',
                    visible: true,
                    formatter: function(value, row, index){
                        if(value == null){
                            return 0;
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'billOutTaskQuantity',
                    title: '实际出库量',
                    align: 'center',
                    visible: true,
                    formatter: function(value, row, index){
                        if(value == null){
                            return 0;
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'boxQuantityHistory',
                    title: '历史库存数',
                    align: 'center',
                    visible: true,
                    formatter: function(value, row, index){
                        if(value == null){
                            return 0;
                        }else{
                            return value;
                        }
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function queryParams(params){
        return {
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            orderByColumn: params.sort,
            isAsc: params.order,
            startTime: app.startTimeValue,
            endTime: app.endTimeValue
        };
    }
</script>
</body>
</html>
